<?php
namespace App\Http\Controllers;

use App\Models\Order;
use Cookie;
use App\Models\User;
use App\Models\TailReport;
use App\Models\OrderUserData;
use App\Models\UserReport;
use App\Models\Setting;
use App\Models\ProductConfig;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use zgldh\QiniuStorage\QiniuStorage;
use App\Admin\Controllers\QiniuAuth;
use Encore\Admin\Facades\Admin;
use GuzzleHttp\Client as GuzzleClient;
use App\Admin\Controllers\CommonController as AdminCommonController;
class ReportController extends Controller
{
    public function checkLogin(Request $request)
    {
        $return['code'] = -1;
        $return['text'] = '无效访问';
        $uid = $request->input('uid', '');
        $auditor_id = Admin::user()->id;
        $merchant = Admin::user()->tenant_id;
        $hasAuth = Admin::user()->inRoles(['administrator', 'admin', 'auditor', 'financial', 'localcollection']);
        if(empty($auditor_id)) {
            $return['text'] = "非法访问";
            exit(json_encode($return));
        }
        if(!$hasAuth){
            $return['text'] = "非法访问";
            exit(json_encode($return));
        }
    }
    //用户基础信息
    public function userinfo(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = 0;
        $return['text'] = '';
        $return['data'] = array();

        $uid = intval($request->input('uid',''));
        $merchant = intval($request->input('merchant',''));
        if(!empty($uid)) {
            $user = User::select("verify_name")->where("id","=",$uid)->where('tenant_id', $merchant)->first();
            if(!empty($user)) {
                $return['data'] = $user;
            }
        }
        return $return;

    }
    public function messages(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = 0;
        $return['text'] = '';
        $return['data'] = array();
        $uid = intval($request->input('uid',''));
        $oid = intval($request->input('oid',''));
        if(!empty($uid)) {
            $user = User::select("verify_name","phone_messages")->where("id","=",$uid)->first();
        } else {
            $user = OrderUserData::where("order_id","=",$oid)->first();
        }

        if(!empty($user)) {
            $arr = json_decode($user['phone_messages'],true);
            if(!empty($arr)) {
                $product_config = ProductConfig::first();
                $contact_switch = $product_config->filter;
                foreach ($arr as $key => $val) {
                    $arr[$key]['date'] = date("Y-m-d H:i:s",substr($val['date'], 0, 10));
//                    if($contact_switch == 1){
                    $arr[$key]['phone'] = substr_replace($val['phone'], '***', '3', '4');
//                    }elseif($contact_switch == 2){
//                        $arr[$key]['phone'] = $val['phone'];
//                    }
                }
            }
            $return['data']['verify_name'] = $user['verify_name'];
            $return['data']['count'] = count($arr);
            $return['data']['list'] = $arr;
        }
        return $return;

    }
    public function contacts(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = 0;
        $return['text'] = '';
        $return['data'] = array();
        $uid = intval($request->input('uid',''));
        $oid = intval($request->input('oid',''));
        if(!empty($uid)) {
            $user = User::select("verify_name","phone_contacts")->where("id","=",$uid)->first();
        } else {
            $user = OrderUserData::where("order_id","=",$oid)->first();
        }
        if(!empty($user)) {
            $contacts = [];
            $return['data']['verify_name'] = $user['verify_name'];
            if(!empty($user['phone_contacts'])) {
                $product_config = ProductConfig::first();
                $contact_switch = $product_config->filter;
                $arr = json_decode($user['phone_contacts'],true);
                foreach ($arr as $key => $val){
//				    if($contact_switch == 1){
                    if(mb_strlen($key) > 8){
                        $key = substr_replace($key, '***', 3, 4);
                    }
//                    }
                    $contacts[$key] = $val;
                }
            }
            $return['data']['count'] = count($contacts);
            $return['data']['list'] = $contacts;
        }
        return $return;

    }
    public function index(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = 0;
        $return['text'] = '';
        $return['data'] = array();
        $uid = intval($request->input('uid',''));
        $oid = intval($request->input('oid',''));

        if(!empty($uid)) {
            $user = User::where("id","=",$uid)->first();
        } else {
            $user = OrderUserData::where("order_id","=",$oid)->first();
        }

        if(!empty($user)) {
            $userdata['mobile'] = $user['mobile'];
            $userdata['verify_name'] = $user['verify_name'];
            $userdata['verify_bankcard_mobile'] = $user['verify_bankcard_mobile'];
            $userdata['verify_idcard_no'] = $user['verify_idcard_no'];
            $userdata['verify_bankcard_no'] = $user['verify_bankcard_no'];
            $userdata['company_name'] = $user['company_name'];
            $userdata['company_tel'] = $user['company_tel'];
            $userdata['company_address'] = $user['company_address'];
            $userdata['phone_location'] = $user['phone_location'];
            $userdata['model'] = $user['model'];
            $userdata['synthesis'] = $user['synthesis'];
            $userdata['platform'] = $user['platform'];

//            $userdata['verify_idcard1_url'] = $user['verify_idcard1_url'];
//            $userdata['verify_idcard2_url'] = $user['verify_idcard2_url'];
//            $userdata['verify_alive_url'] = $user['verify_alive_url'];

            $qiniu_obj = new QiniuAuth();
            
            $userdata['verify_idcard1_url'] = $qiniu_obj->getToken($user['verify_idcard1_url']);
            $userdata['verify_idcard2_url'] = $qiniu_obj->getToken($user['verify_idcard2_url']);
            $userdata['verify_alive_url'] = $qiniu_obj->getToken($user['verify_alive_url']);

            $userdata['idcard_ok'] = $user['idcard_ok'];
            $userdata['alive_ok'] = $user['alive_ok'];
            $userdata['verify_pay_weixin'] = $user['verify_pay_weixin'];
            $userdata['verify_pay_zhifubao'] = $user['verify_pay_zhifubao'];

            $userdata['emergency_contact1_type'] = $user['emergency_contact1_type'];
            $userdata['emergency_contact1_name'] = $user['emergency_contact1_name'];
            $userdata['emergency_contact1_mobile'] = $user['emergency_contact1_mobile'];
            $userdata['emergency_contact2_type'] = $user['emergency_contact2_type'];
            $userdata['emergency_contact2_name'] = $user['emergency_contact2_name'];
            $userdata['emergency_contact2_mobile'] = $user['emergency_contact2_mobile'];

            $userdata['live_address'] = $user['reside_city'].' '. $user['reside_address'];
            $userdata['phone_location_address'] = $user['phone_location_address'];
            $user['phone_appnames'] = json_decode($user['phone_appnames'], true);
            $userdata['phone_appnames'] = '';
            $appnames_str = '';
            if(!empty($user['phone_appnames'])) {
                $appnames_arr = $user['phone_appnames'];
                $appnames_arr_new = array();
                foreach ($appnames_arr as $_key => $_val) {
                    $appnames_arr_new[$_val['packagename']] = $_val['appname'] . ", ";
                }
                foreach ($appnames_arr_new as $_key => $_val) {
                    $appnames_str .= $_val . ", ";
                }
            }
            $userdata['phone_appnames'] = rtrim($appnames_str, ',');

            $return['data']['user'] = $userdata;

        }

        return $return;

    }
    public function base(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = 0;
        $return['text'] = '';
        $return['data'] = array();

        $uid = intval($request->input('uid',''));
        $oid = intval($request->input('oid',''));
        if(!empty($uid)) {
            $user = User::where("id","=",$uid)->first();
        } else {
            $user = OrderUserData::where("order_id","=",$oid)->first();
        }
        if(!empty($user)) {
            $return['data']['uid'] = $user['id'];

            $return['data']['mobile'] = $user['mobile'];
            $return['data']['verify_name'] = $user['verify_name'];
            $return['data']['verify_bankcard_mobile'] = $user['verify_bankcard_mobile'];
            $return['data']['verify_idcard_no'] = $user['verify_idcard_no'];
            $return['data']['verify_bankcard_no'] = $user['verify_bankcard_no'];
//            $return['data']['verify_idcard1_url'] = substr($user['verify_idcard1_url'],0,strpos($user['verify_idcard1_url'],"?imageMogr2"));
//            $return['data']['verify_idcard2_url'] = substr($user['verify_idcard2_url'],0,strpos($user['verify_idcard2_url'],"?imageMogr2"));

            $return['data']['verify_idcard1_url'] = $user['verify_idcard1_url'];
            $return['data']['verify_idcard2_url'] = $user['verify_idcard2_url'];



            $return['data']['emergency_contact1_type'] = $user['emergency_contact1_type'];
            $return['data']['emergency_contact1_name'] = $user['emergency_contact1_name'];
            $return['data']['emergency_contact1_mobile'] = $user['emergency_contact1_mobile'];
            $return['data']['emergency_contact2_type'] = $user['emergency_contact2_type'];
            $return['data']['emergency_contact2_name'] = $user['emergency_contact2_name'];
            $return['data']['emergency_contact2_mobile'] = $user['emergency_contact2_mobile'];

            $return['data']['company_name'] = $user['company_name'];
            $return['data']['company_tel'] = $user['company_tel'];
            $return['data']['company_address'] = $user['company_address'];
            $return['data']['reside_city'] = $user['reside_city'];
            $return['data']['reside_address'] = $user['reside_address'];
            $return['data']['phone_appnames'] = $user['phone_appnames'];
            $appnames_arr = json_decode($user['phone_appnames'],true);
            $appnames_str = '';
            if(!empty($appnames_arr)) {
                $appnames_arr_new = array();
                foreach ($appnames_arr as $_key => $_val) {
                    $appnames_arr_new[$_val['packagename']] = $_val['appname'] . ", ";
                }
                foreach ($appnames_arr_new as $_key => $_val) {
                    $appnames_str .= $_val . ", ";
                }
                $return['data']['phone_appnames'] = $appnames_str;
            }

            $return['data']['verify_alive_url'] = $user['verify_alive_url'];

        }
        return $return;

    }

    public function carrierData(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = -1;
        $return['text'] = '暂无报告';
        $return['data'] = '';
        $uid = intval($request->input('uid',''));
        $oid = 0;//intval($request->input('oid',''));
        if(empty($oid)) {
            $user = User::select("verify_name")->where("id","=",$uid)->first();
            $row = UserReport::select("data")->where("user_id",'=',$uid)->where("apiname",'=','carrier')->first();
        } else {
            $user = OrderUserData::select("report_carrier_data")->where("order_id","=",$oid)->first();
            $row['data'] = $user['report_carrier_data'];
        }
        //dd($row);
        if(!empty($user)) {
            if(!empty($row)) {
                $return['code'] = 0;
                $data = json_decode($row['data'],true);
                //dd($row['data']);
                if(!empty($data)) {
                    if(!isset($data['data']['carrierUserInfo'])) {
                        $data['data']['carrierUserInfo']['packageName'] = "";
                        $data['data']['carrierUserInfo']['city'] = "";
                        $data['data']['carrierUserInfo']['point'] = "";
                        $data['data']['carrierUserInfo']['availableBalance'] = "";
                    }
                    $return['text'] = '成功';
                    $return['data'] = $data;
                }

            }
        }
        return $return;

    }

    public function carrier(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = -1;
        $return['text'] = '暂无报告';
        $return['data'] = '';
        $uid = intval($request->input('uid',''));
        $logined = intval(session("logined"));
        //echo "$uid,$logined";
        if(!empty($uid)) {
            $oid = 0;//intval($request->input('oid',''));
            if(empty($oid)) {
                $user = User::where("id","=",$uid)->first();
                $row = UserReport::where("user_id",'=',$uid)->where("apiname",'=','carrier')->first();
            } else {
                $user = OrderUserData::where("order_id","=",$oid)->first();
                $row['datareport'] = $user['report_carrier_data'];
            }

            //dd($row['datareport']);
            if(!empty($row)) {
                $return['code'] = 0;
                $data = json_decode($row['datareport'],true);
                if(!empty($data)) {
                    $phone_contacts = json_decode($user['phone_contacts'],true);//手机通讯录
                    $data['verify_name'] = $user->verify_name;
                    $data['user_basic_info']['verify_idcard_no_desc'] = '<span style="color: red;">失败</span>';
                    $data['user_basic_info']['verify_name_desc'] =  '<span style="color: red;">失败</span>';
                    if($data['user_basic_info']['idcard'] == $user['verify_idcard_no']) {
                        $data['user_basic_info']['verify_idcard_no_desc'] = '<span style="color: green;">成功</span>';
                    }

                    if(empty($data['user_basic_info']['name'])) {
                        $data['user_basic_info']['name'] = $data['user_basic_info']['name_from_custom'];
                    }
                    if($data['user_basic_info']['name'] == $user['verify_name']) {
                        $data['user_basic_info']['verify_name_desc'] = '<span style="color: green;">成功</span>';
                    }
                    //匹配通讯录
                    if(isset($data['friend_circle']['call_num_top10_3m'])) {
                        foreach ($data['friend_circle']['call_num_top10_3m'] as $key => $val) {
                            $peer_number = $val['peer_number'];
                            $data['friend_circle']['call_num_top10_3m'][$key]['peer_name'] = '';
                            if(isset($phone_contacts[$peer_number])) {
                                $data['friend_circle']['call_num_top10_3m'][$key]['peer_name'] = $phone_contacts[$peer_number];
                            }
                        }
                    }

                    //匹配通讯录
                    if(isset($data['friend_circle']['call_num_top10_6m'])) {
                        foreach ($data['friend_circle']['call_num_top10_6m'] as $key => $val) {
                            $peer_number = $val['peer_number'];
                            $data['friend_circle']['call_num_top10_6m'][$key]['peer_name'] = '';
                            if(isset($phone_contacts[$peer_number])) {
                                $data['friend_circle']['call_num_top10_6m'][$key]['peer_name'] = $phone_contacts[$peer_number];
                            }
                        }
                    }

                    $return['text'] = '成功';
                    $return['data'] = $data;
                }

            }
        }
        return $return;

    }

    public function taobao(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = -1;
        $return['text'] = '暂无报告';
        $return['data'] = '';
        $uid = intval($request->input('uid',''));
        $logined = intval(session("logined"));
        //echo "$uid,$logined";
        if(!empty($uid)) {

            $oid = intval($request->input('oid',''));
            if(!empty($uid)) {
                $user = User::select("verify_name")->where("id","=",$uid)->first();
                $row = UserReport::where("user_id",'=',$uid)->where("apiname",'=','taobaoweb')->first();
            } else {
                $user = OrderUserData::where("order_id","=",$oid)->first();
                $row['datareport'] = $user['report_taobaoweb_data'];
            }

            if(!empty($row)) {
                $return['code'] = 0;
                $return['text'] = '成功';
                $data = json_decode($row['datareport'],true);
                if(!empty($data)) {
                    $data['verify_name'] = $user->verify_name;
                }
                $return['data'] = $data;
            }
        }
        return $return;

    }

    public function radar(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = -1;
        $return['text'] = '暂无报告';
        $return['data'] = '';
        $uid = intval($request->input('uid',''));
        $logined = intval(session("logined"));
        //echo "$uid,$logined";
        if(!empty($uid)) {


            $oid = 0;//intval($request->input('oid',''));
            if(empty($oid)) {
                $user = User::select("verify_name")->where("id","=",$uid)->first();
                $row = UserReport::where("user_id",'=',$uid)->where("apiname",'=','radar')->first();
            } else {
                $user = OrderUserData::where("order_id","=",$oid)->first();
                $row['datareport'] = $user['report_radar_data'];
            }

            if(!empty($row)) {
                $return['code'] = 0;
                $return['text'] = '成功';
                $data = json_decode($row['datareport'],true);
                if(!empty($data)) {
                    $data['verify_name'] = $user->verify_name;
                }
                if(!isset($data['result_detail']['behavior_report_detail']['loans_score'])) {
                    $data['result_detail']['behavior_report_detail']['loans_score'] = '';
                    $data['result_detail']['behavior_report_detail']['loans_credibility'] = '';
                    $data['result_detail']['behavior_report_detail']['loans_count'] = '';
                    $data['result_detail']['behavior_report_detail']['loans_settle_count'] = '';
                    $data['result_detail']['behavior_report_detail']['loans_overdue_count'] = '';
                    $data['result_detail']['behavior_report_detail']['loans_org_count'] = '';
                    $data['result_detail']['behavior_report_detail']['consfin_org_count'] = '';
                    $data['result_detail']['behavior_report_detail']['loans_cash_count'] = '';
                    $data['result_detail']['behavior_report_detail']['latest_one_month'] = '';
                    $data['result_detail']['behavior_report_detail']['latest_three_month'] = '';
                    $data['result_detail']['behavior_report_detail']['latest_six_month'] = '';
                    $data['result_detail']['behavior_report_detail']['history_suc_fee'] = '';
                    $data['result_detail']['behavior_report_detail']['history_fail_fee'] = '';
                    $data['result_detail']['behavior_report_detail']['latest_one_month_suc'] = '';
                    $data['result_detail']['behavior_report_detail']['latest_one_month_fail'] = '';
                    $data['result_detail']['behavior_report_detail']['loans_long_time'] = '';
                    $data['result_detail']['behavior_report_detail']['loans_latest_time'] = '';
                }
                if(!isset($data['result_detail']['current_report_detail']['loans_credit_limit'])) {
                    $data['result_detail']['current_report_detail']['loans_credit_limit'] = '';
                    $data['result_detail']['current_report_detail']['loans_credibility'] = '';
                    $data['result_detail']['current_report_detail']['loans_org_count'] = '';
                    $data['result_detail']['current_report_detail']['loans_product_count'] = '';
                    $data['result_detail']['current_report_detail']['loans_max_limit'] = '';
                    $data['result_detail']['current_report_detail']['loans_avg_limit'] = '';
                    $data['result_detail']['current_report_detail']['consfin_credit_limit'] = '';
                    $data['result_detail']['current_report_detail']['consfin_credibility'] = '';
                    $data['result_detail']['current_report_detail']['consfin_org_count'] = '';
                    $data['result_detail']['current_report_detail']['consfin_product_count'] = '';
                    $data['result_detail']['current_report_detail']['consfin_max_limit'] = '';
                    $data['result_detail']['current_report_detail']['consfin_avg_limit'] = '';
                }
                if(!isset($data['result_detail']['apply_report_detail']['apply_score'])) {
                    $data['result_detail']['apply_report_detail']['apply_score'] = '';
                    $data['result_detail']['apply_report_detail']['apply_credibility'] = '';
                    $data['result_detail']['apply_report_detail']['query_org_count'] = '';
                    $data['result_detail']['apply_report_detail']['query_finance_count'] = '';
                    $data['result_detail']['apply_report_detail']['query_cash_count'] = '';
                    $data['result_detail']['apply_report_detail']['query_sum_count'] = '';
                    $data['result_detail']['apply_report_detail']['latest_query_time'] = '';
                    $data['result_detail']['apply_report_detail']['latest_one_month'] = '';
                    $data['result_detail']['apply_report_detail']['latest_three_month'] = '';
                    $data['result_detail']['apply_report_detail']['latest_six_month'] = '';

                }
                $return['data'] = $data;
            }
        }
        return $return;
    }

    //统计尾量转化的数据
    public function tailReport(Request $request){
        $uid = session('uid');
        if(!$uid){
            return ['code' => -1, 'text' => 'error'];
        }
        $channel_id = $request->input('cid');
        if(!$channel_id){
            return ['code' => -1, 'text' => 'error'];
        }

        $today = date('Y-m-d');
        $tailReport = TailReport::where('date', $today)->where('channel_id', $channel_id)->first();
        if(!count($tailReport)){
            $tailReport = new TailReport();
            $tailReport->date = $today;
            $tailReport->channel_id = $channel_id;
        }

        $ip = $_SERVER['REMOTE_ADDR'];
        $ip_collectors = @file_get_contents('../storage/report/tail_'.$channel_id.date('Ymd').'.log');//获取ip地址
        if(stripos($ip_collectors, $ip) === false){
            $cookie = $request->cookie('tail_uv'.$channel_id);
            if(!$cookie){
                $tailReport->uv++;
                $minites = (strtotime(date('Y-m-d').' 23:59:59') - time())/60;
                Cookie::queue('tail_uv'.$channel_id, 'tail_uv', $minites);
            }
            @file_put_contents('../storage/report/tail_'.$channel_id.date('Ymd').'.log', $ip.','.PHP_EOL, FILE_APPEND);//保存ip地址
        }
        $tailReport->pv++;
        $tailReport->save();
        return ['code' => 0];
    }

    //发送请求
    public function guzzle($url, $params)
    {
        $client = new GuzzleClient([
            // 超时
            'timeout' => 60.0,

        ]);
        return $client->request('GET', $url, $params);
    }

    public function guzzle_post($url, $params){
        $client = new GuzzleClient([
            // 超时
            'timeout' => 60.0,
        ]);
        return $client->request('POST', $url, $params);
    }

    //布尔报告多头借贷,布尔报告特殊关注名单
    public function buerReport(Request $request){
        try{
            $merchant = $request->merchant;
            $uid = $request->uid;
            $user = User::where('id', $uid)->where('tenant_id', $merchant)->first();
            if(!count($user)) return ['code' => 1];;
            if(!$user['verify_name'] || !$user['verify_idcard_no'] || !$user['mobile']){
                return ['code' => 1];;
            }

            $get_url = env('RISKDECISION').'/risk/Report/GetMultiplePlatformsLoan';
            $get_list_url = env('RISKDECISION').'/risk/Report/GetPersonalFraudBlacklist';
            $params = [
                'form_params' => [
                    'name' => $user['verify_name'],
                    'ident_number' => $user['verify_idcard_no'],
                    'phone' => $user['mobile'],
                ],
                'headers' => [
                    'ident' => 'production'
                ],
            ];

            //扣费
            $adminCommonController = new AdminCommonController();
            $admres = $adminCommonController->commonChangeFee($user['tenant_id'], 'buer_fee', $uid, 10);
            if($admres['code']){
                return ['code' => 1, 'text' => $admres['text']];
            }

            $config_data = $this->guzzle_post($get_url, $params);
            $res['duotou'] = json_decode($config_data->getBody()->getContents(), true);
            if(!isset($res['duotou']['data'])){
                $res['duotou']['data'] = [];
                $res['duotou']['show'] = false;
            }else{
                $res['duotou']['show'] = true;
            }
            $res['duotou']['show'] = true;

            $config_list_data = $this->guzzle_post($get_list_url, $params);
            $res['list'] = json_decode($config_list_data->getBody()->getContents(), true);
            if(!isset($res['list']['data'])){
                $res['list']['data'] = [];
                $res['list']['show'] = false;
            } else{
                $res['list']['show'] = true;
            }

            $res['userinfo'] = $user;

            file_put_contents('../storage/risk/buer_res'.date('Ymd').'.log', date('Y-m-d H:i:s').'_'.json_encode($res).PHP_EOL, FILE_APPEND);

            return ['code' => 0, 'data' => $res];
        }catch (\Exception $ex){
            file_put_contents('../storage/risk/buer_error'.date('Ymd').'.log', date('Y-m-d H:i:s').'_'.$ex->getMessage().PHP_EOL, FILE_APPEND);
            return ['code' => 1, 'text' => '数据异常'];
        }
    }

    //获取通话记录
    public function calllog(Request $request)
    {
        $this->checkLogin($request);
        $return['code'] = 0;
        $return['text'] = '';
        $return['data'] = array();
        $uid = intval($request->input('uid',''));
        $user = User::select("verify_name","call_log")->where("id","=",$uid)->first();
        if(!count($user)) return ['code' => 0, 'text' => '用户不存在'];

        $arr = json_decode($user['call_log'],true);
        if(!empty($arr)) {
            $product_config = ProductConfig::first();
//            $contact_switch = $product_config->filter;
            $contact_switch = 1;
            foreach ($arr as $key => $val) {
                $arr[$key]['name'] = $val['name'];
                $arr[$key]['time'] = $val['time'];
                $arr[$key]['date'] = $val['date'];
                if($contact_switch == 1){
                    $arr[$key]['phone'] = substr_replace($val['phone'], '***', '3', '4');
                }elseif($contact_switch == 2){
                    $arr[$key]['phone'] = $val['phone'];
                }
            }
        }
        $return['data']['verify_name'] = $user['verify_name'];
        $return['data']['count'] = count($arr);
        $return['data']['list'] = $arr ?? [];

        return $return;
    }
}